import java.util.Arrays;

public class MyStack {
    //数组栈
    public int[] val;
    public int UseSize;

     public MyStack() {
        this.val = new int[10];
    }

    public void push(int x){
        if(this.val.length == UseSize){
            this.val = Arrays.copyOf(this.val,this.val.length*2);
        }
        this.val[this.UseSize++] = x;
    }

    public int pop(){
         int val = 0;
        if(empty()){
            throw new StackEmptyException("栈为空");
        }
        val = this.val[this.UseSize-1];
        this.UseSize--;

        return val;
    }

    public boolean empty(){
        return this.UseSize == 0;
    }

    public int peek(){
        if(empty()){
            throw new StackEmptyException("栈为空");
        }
        return this.val[UseSize-1];
    }

    public int size(){
        return this.UseSize;
    }

}
